package com.maisha.msTag;

import java.io.IOException;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import com.maisha.utils.CMSConstant;

public class CMSPowerTag extends BodyTagSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String codeName;

	public String getCodeName() {
		return codeName;
	}

	public void setCodeName(String codeName) {
		this.codeName = codeName;
	}
	
	
	@Override
	public int doEndTag() throws JspException {
		JspWriter out = bodyContent.getEnclosingWriter();
		String result = bodyContent.getString();
		//从session 中获得用户的 登录权限
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		Map<String,Object> auditPower = (Map<String, Object>) request.getSession().getAttribute(CMSConstant.AUDIT_POWER_KEY);
		// 判断用户是否合法
		try {
			if(auditPower!=null && auditPower.size() > 0 && auditPower.containsKey(codeName)){
				out.print(result);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return SKIP_BODY;
	}
	
}
